package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;



    /**
     * 订单搜索
     */
    @GetMapping("/conditionSearch")
//    @ModelAttribute 注解可用于将请求参数绑定到一个 Java 对象上，适合接收多个查询参数并封装成对象。
    public Result<PageResult> pageSearch(@ModelAttribute  OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单搜索，传递来的参数是{}",ordersPageQueryDTO);
        PageResult pageResult = orderService.search(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     *  订单详细信息
     */
    @GetMapping("/details/{id}")
    public Result<Orders> getById(@PathVariable Long id) {
        log.info("订单详细信息，传递来的参数是{}",id);
        Orders orders = orderService.getById(id);
        return  Result.success(orders);

    }

    /**
     * 各个状态的订单数量
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getStatistics() {
        log.info("各个状态的订单数量");
        OrderStatisticsVO orderStatisticsVO = orderService.getStatistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 接单
     * @param
     */
    @PutMapping("/confirm")
    public Result confirm( @RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("订单确认，传递来的参数是{}",ordersConfirmDTO);
        orderService.confirm(ordersConfirmDTO.getId());
        return Result.success();
    }
    /**
     * 拒单
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("订单拒单，传递来的参数是{}",ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    public Result cancle(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("订单取消，传递来的参数是{}",ordersCancelDTO);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 完成订单
     */

    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id) {
        log.info("完成的订单id是{}",id);
        orderService.complete(id);
        return Result.success();
    }

    /**
     * 派送订单
     */

    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id) {
        log.info("派送的订单id是{}",id);
        orderService.delivery(id);
        return Result.success();
    }

}
